package com.example.zhidao.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.zhidao.model.po.Chat;
import com.example.zhidao.model.vo.InfoVo;
import com.github.yulichang.base.MPJBaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;


public interface ChatMapper extends BaseMapper<Chat> {

@Select("\n" +
        "select u.img,u.username,t.time,t.uid,t.state from user u join \n" +
        "(select * from chat c join(\n" +
        "select  fromid uid\n" +
        ",max(createtime) as time from chat \n" +
        " WHERE  toid = #{id}\n" +
        "GROUP BY fromid ) as g on c.createtime=g.time and c.fromid=g.uid) as t on u.id=t.uid order by t.time desc ")
@Results({
        @Result(property = "uid", column = "uid"),
        @Result(property = "username", column = "username"),
        @Result(property = "time", column = "time"),
        @Result(property = "img", column = "img"),
        @Result(property = "state", column = "state"),

        // 其他属性映射规则...
})
List<InfoVo> selinfoList(String id);



//上面这个是查全部的，下面的使用分页
@Select("\n" +
        "select u.img,u.username,t.time,t.uid,t.state from user u join \n" +
        "(select * from chat c join(\n" +
        "select  fromid uid\n" +
        ",max(createtime) as time from chat \n" +
        " WHERE  toid = #{id}\n" +
        "GROUP BY fromid ) as g on c.createtime=g.time and c.fromid=g.uid) as t on u.id=t.uid order by t.time desc LIMIT  #{pageNum}, #{pageSize}")
@Results({
        @Result(property = "uid", column = "uid"),
        @Result(property = "username", column = "username"),
        @Result(property = "time", column = "time"),
        @Result(property = "img", column = "img"),
        @Result(property = "state", column = "state"),

        // 其他属性映射规则...
})
List<InfoVo> selinfoListPage(String id,@Param("pageNum")int pageName, @Param("pageSize")int pageSize);
}
